import logging

import src.global_config as gl
import os


class Log:

    def __init__(self):
        # 获取日志级别
        LOG_FORMAT = "%(asctime)s - %(levelname)s - %(message)s"
        DATE_FORMAT = "%m/%d/%Y %H:%M:%S %p"
        logpath = gl.get_value('logpath')
        try:
            os.mkdir(logpath + '/log')
        except FileExistsError:
            pass
        logpath = logpath + '/log/honinbo.log'
        logging.basicConfig(filename=logpath, level=logging.NOTSET, format=LOG_FORMAT, datefmt=DATE_FORMAT)

    # 调试
    @staticmethod
    def todebug(data):
        print(data)
        logging.debug(data)

    # 日志
    @staticmethod
    def toinfo(data):
        print(data)
        logging.info(data)

    # 警告
    @staticmethod
    def towarn(data):
        print(data)
        logging.warning(data)

    # 空枪
    @staticmethod
    def toerror(data):
        print(data)
        logging.error(data)

    # 致命空枪
    @staticmethod
    def tocrit(data):
        print(data)
        logging.critical(data)
